include $(QUEX_PATH)/quex/code_base/core.mkd

# (*) SETUP ____________________________________________________________________
#
# QUEX_PATH    = ../../ # there should be an environment variable 'QUEX_PATH'
#                       # thus this does have to be defined explicitly here.
#
# -- INPUT
DEBUG_F= -ggdb # set flag if debugging info is required

# -- APPLICATION / LIBRARY specification
APPLICATION_NAME = depythonize_c
LIBRARY_NAME     = libdepythonize_c
ENGINE_NAME      = depythonize_c_lex# NOTE: a whitespace after this name creates chaos!
#
ENGINE_SOURCES   = $(ENGINE_NAME)                     \
                   $(ENGINE_NAME).cpp                 \
                   $(ENGINE_NAME)-token_ids           \
                   $(ENGINE_NAME)-configuration       
#
LIBRARY_OBJS     = $(ENGINE_NAME).o


ENABLE_WARNINGS= #-Wall #set flag for showing warnings

# (*) COMPILER SETTINGS ________________________________________________________
#     (change COMPILER to whatever you use as compiler on the command line,
#     e.g. "make COMPILER=icpc" will use intel's c++ compiler)
COMPILER = g++
# -- compiler
CC = $(COMPILER) -c -fPIC -ggdb -Wno-deprecated $(ENABLE_WARNINGS) \
	 -I./ -I$(QUEX_PATH) $(DEBUG_F)      \
	 -DQUEX_OPTION_ASSERTS_WARNING_MESSAGE_DISABLED
	 #-DQUEX_OPTION_DEBUG_MODE_TRANSITIONS \
	 #-D__QUEX_OPTION_DEBUG_STATE_TRANSITION_REPORTS

# -- linker
LD         = $(COMPILER)
STATIC_LD  = ar -rv
DYNAMIC_LD = $(COMPILER) -shared 

# (*) RULES ____________________________________________________________________
#
# -- application
$(APPLICATION_NAME): $(APPLICATION_NAME).o program_mode.o preprocessor_mode.o debug_print.o util.o $(ENGINE_NAME).o
	$(LD) $(^) -o $(APPLICATION_NAME)

# -- libraries
$(LIBRARY_NAME).so: $(LIBRARY_NAME).o translate.o program_mode.o preprocessor_mode.o debug_print.o util.o $(ENGINE_NAME).o
	$(DYNAMIC_LD) $(^) -o $@
	cp $(LIBRARY_NAME).so ../lib/

$(LIBRARY_NAME).a: $(LIBRARY_NAME).o translate.o program_mode.o preprocessor_mode.o debug_print.o util.o $(ENGINE_NAME).o
	$(STATIC_LD) $@ $(LIBRARY_OBJS)
	cp $(LIBRARY_NAME).a ../lib/

# -- engine and object files
$(APPLICATION_NAME).o: $(APPLICATION_NAME).cpp $(ENGINE_SOURCES)
#       # require: $(ENGINE_SOURCES) for header files
	$(CC) $(APPLICATION_NAME).cpp -o $(APPLICATION_NAME).o

$(ENGINE_NAME).o: $(ENGINE_SOURCES)
	$(CC) $(ENGINE_NAME).cpp -o $(ENGINE_NAME).o

%.o: %.cpp
	$(CC) $< -o $@

$(ENGINE_SOURCES): $(MODE_FILES) $(QUEX_CORE)
	quex --mode-files $(MODE_FILES)    \
	     --engine     $(ENGINE_NAME)   

clean:	
	rm -f *.o $(APPLICATION_NAME) *~ $(LIBRARY_NAME).so $(LIBRARY_NAME).a
